package com.hengxinguotong.hxgtwygsp.ui.base;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import javax.inject.Inject;

import butterknife.ButterKnife;
import dagger.android.AndroidInjection;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasFragmentInjector;
import dagger.android.support.HasSupportFragmentInjector;

/**
 * TODO
 *
 * @author hjz
 * @version V1.0.0
 * @since 2018/12/22 10:22
 */

public abstract class BaseActivity extends RxAppCompatActivity implements HasFragmentInjector, HasSupportFragmentInjector
{
    @Inject
    DispatchingAndroidInjector<Fragment> mFrameworkFragmentInjector;
    @Inject
    DispatchingAndroidInjector<android.support.v4.app.Fragment> mSupportFragmentInjector;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        AndroidInjection.inject(this);
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        ButterKnife.bind(this);
        init();
    }

    /**
     * 获取布局文件的资源ID
     *
     * @return int
     * @author hjz
     * @since 2019/1/8 16:00
     */
    public abstract int getLayoutResId();

    /**
     * 初始化操作
     *
     * @return void
     * @author hjz
     * @since 2019/1/8 16:00
     */
    public abstract void init();

    @Override
    public AndroidInjector<Fragment> fragmentInjector()
    {
        return mFrameworkFragmentInjector;
    }

    @Override
    public AndroidInjector<android.support.v4.app.Fragment> supportFragmentInjector()
    {
        return mSupportFragmentInjector;
    }
}
